<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工等级管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['lev_name'])){
		$params['lev_name like']='%'.trim($_RQ['lev_name']).'%';
		$return['params']['lev_name']=$_RQ['lev_name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','lev_name','lev','paixu','createtime');
	$list=pdo_getslice('jy_cmsdecorate_lev',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'等级列表'),
			array('op'=>'edit','title'=>'添加等级'),
		),
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'lev_name','title'=>'等级名称','type'=>'string'),
			array('name'=>'lev','title'=>'等级','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'lev_name','title'=>'等级名称','type'=>'string','width'=>'15'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_cmsdecorate_lev',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回等级列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'等级名称','name'=>'lev_name','help'=>'','ismust'=>true),
					array('type'=>'string','title'=>'等级','name'=>'lev','help'=>''),
					array('type'=>'string','title'=>'排序','name'=>'paixu','help'=>'填写数字，按从小到大排序展示'),
				)
			),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(empty($postdata['lev_name'])){
		exi('请完善等级名称','error');
	}
	$data=array(
		'lev_name'=>trim($postdata['lev_name']),
		'lev'=>intval($postdata['lev']),
		'paixu'=>intval($postdata['paixu']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_cmsdecorate_lev',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_cmsdecorate_lev',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_cmsdecorate_lev',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}